extends Area2D

var damage = 10
#存储速度方向
var speed_direction = Vector2()

#创建信号
signal attack_collided(damage)

func _spawn_ready() -> void:
	#获得鼠标和节点相对位置,计算为速度方向
	var relative_position = to_local(get_global_mouse_position())
	speed_direction = relative_position.normalized()
	self.rotation = get_parent().rotation
	await get_tree().create_timer(3).timeout
	queue_free()

func _physics_process(delta: float) -> void:
	#子弹移动逻辑
	position += speed_direction * delta * 750

func _on_area_entered(area: Area2D) -> void:
	#检测碰撞，发出信号
	if area.is_in_group("enemy"):
		area.emit_signal("hurt", damage)
		queue_free()
